﻿@using System.Globalization
@using Lari.Configuration
@using Lari.Web.Utility
@model Lari.Services.ViewModel.ListModel<Lari.Services.ViewModel.QualificationModel>
@helper BuildLinks(int start, int end, string innerContent)
    {
        for (int i = start; i <= end; i++)
        {
            if (i == Model.CurrentPage)
            {
                <text>
                @i.ToString(CultureInfo.InvariantCulture)
                </text>         
            }
            else
            {
                <a href="@Url.Action(ActionConst.Masters.Hr.Qualifications, ControllerConst.Masters.HRMaster, new { currentPage = i })">@(innerContent ?? i.ToString(CultureInfo.InvariantCulture))</a> 
            }

        }
     
}
@helper BuildPaginations()
    {
        if (Model.TotalPageCount <= ApplicationConfig.ShowTotalPage)
        {
    @BuildLinks(1, Model.TotalPageCount, null)
            return;
        }
        int pagesAfter = Model.TotalPageCount - Model.CurrentPage; // Number of pages after current
        int pagesBefore = Model.CurrentPage - 1; // Number of pages before current

        if (pagesAfter <= 4)
        {
    @BuildLinks(1, 1, null) // Show 1st page

            int pageSubset = Model.TotalPageCount - ApplicationConfig.ShowTotalPage - 1 > 1 ? Model.TotalPageCount - ApplicationConfig.ShowTotalPage - 1 : 2;
    @BuildLinks(pageSubset, pageSubset, "...") // Show page subset (...)
 
    @BuildLinks(Model.TotalPageCount - ApplicationConfig.ShowTotalPage + 3, Model.TotalPageCount, null) // Show last pages

            return; // Exit
        }

        if (pagesBefore <= 4)
        {
    @BuildLinks(1, ApplicationConfig.ShowTotalPage - 2, null) // Show 1st pages


            int pageSubset = ApplicationConfig.ShowTotalPage + 2 < Model.TotalPageCount ? ApplicationConfig.ShowTotalPage + 2 : Model.TotalPageCount - 1;
    @BuildLinks(pageSubset, pageSubset, "...") // Show page subset (...)
 
    @BuildLinks(Model.TotalPageCount, Model.TotalPageCount, null) // Show last page

            return; // Exit

        }
        if (pagesAfter > 4)
        {
    @BuildLinks(1, 1, null) // Show 1st pages

            int pageSubset1 = Model.CurrentPage - 7 > 1 ? Model.CurrentPage - 7 : 2;
            int pageSubset2 = Model.CurrentPage + 7 < Model.TotalPageCount ? Model.CurrentPage + 7 : Model.TotalPageCount - 1;
 
    @BuildLinks(pageSubset1, pageSubset1, pageSubset1 == Model.CurrentPage - 4 ? null : "...") // Show 1st page subset (...)
 
    @BuildLinks(Model.CurrentPage - 3, Model.CurrentPage + 3, null) // Show middle pages

            // Show 2nd page subset (...)
            // only show ... if page is contigous to the previous one.
    @BuildLinks(pageSubset2, pageSubset2, pageSubset2 == Model.CurrentPage + 4 ? null : "...")
    @BuildLinks(Model.TotalPageCount, Model.TotalPageCount, null) // Show last page
        }    
        

}
<div id="pagetitle">
    <h1>@ScreenName.Masters.Qualifications</h1>
</div>
<div class="spacer">
</div>
<div id="pagecontent">
    <div class="spacer">
    </div>
    @if (Model != null && (Model.Result == null || Model.Result.Count == 0))
    {
        <div class="doubleSpacer">
        </div>
        <div style="margin-left: 150px; margin-right: 150px;">
            @Html.Partial("_DisplyMessaage", MessageCode.Generic.NoData)
        </div>
        <div class="doubleSpacer">
        </div>
   
    }
    @if (Model != null && Model.Result != null && Model.Result.Count > 0)
    {
        <table class="webgrid" style="width:50%">
            @* header *@
            <thead>
                <tr class="webgrid-header">
                    <th>
                        Qualification Name
                    </th>
                    <th>
                        Degree Type
                    </th>
                    <th>&nbsp;</th>
                    
                </tr>
            </thead>
            @{int i = 1;}
            @foreach (var p in Model.Result)
            {   
                <tr class="@(i++ % 2 == 0 ? "webgrid-alternating-row" : "webgrid-row-style")">
                    <td>@p.Name
                    </td>
                    
                    <td>@this.LookupInfo(LookupEnum.Qualification, p.Parent)
                    </td>
                    <td>
                        @Html.ActionLink(GuiActionName.Edit,ActionConst.Masters.Hr.ModifyQualification,new{id=p.Id})
                    </td>
                    
                   
                </tr>
            }
            <tfoot>
                <tr class="webgrid-footer">
                    <td colspan="3">
                        <div align="right">
                            @BuildPaginations()
                        </div>
                    </td>
                </tr>
            </tfoot>
        </table>
        
    }
    <div>
        @Html.ActionLink(ScreenName.Masters.CreateQualifications, ActionConst.Masters.Hr.CreateQualification, ControllerConst.Masters.HRMaster)
    </div>
</div>
